<%@ page contentType="text/html;charset=UTF-8" %>
<%@ taglib prefix="uct" uri="/WEB-INF/uct.tld" %>
<%@ taglib prefix="portal" uri="/WEB-INF/portal.tld" %>
<!DOCTYPE html>
<html lang="zh-CN">
<head>
  <meta charset="utf-8">
  <meta http-equiv="X-UA-Compatible" content="IE=edge">
  <%@ include file="/common/sale/include/common-base.jsp"%>
  <script src="/common/sale/bootstrap-menu/BootstrapMenu.min.js"></script>
  <script src="/common/sale/jquery-hotkeys/jquery.hotkeys.js"></script>
  <script src="/common/sale/MsgToos.js"></script>
  <link rel="stylesheet" href="${ctx}/common/sale/base/utils/sale_style.css">
  <script type="text/javascript" src="https://cdn.goeasy.io/goeasy.js"></script>
  <title>委托交易</title>
</head>
<body class="hold-transition ${sysUserColor} sidebar-mini">
<div class="wrapper">
  <!-- top start -->
  <%@include file="/common/sale/top-user.jsp" %>
  <!-- top end -->
<!-- left start -->
  <%@include file="/common/sale/left-user.jsp" %>
<!-- left end-->
 <!-- main start -->
  <div class="content-wrapper">
	  <div class="content" style="padding:0px 15px;">
		  <div class="row">

			  <div class="col-lg-12 quot" style="margin-top:0px;min-height:300px;" >
    				<form id="searchQuotProForm" name="searchQuotProForm">
						<input type="hidden" name="pageName" value="t-quotation"/>
						<input type="hidden" name="formName" value="searchForm"/>
						<input type="hidden" name="tQuotation.status" value="T"/>
						<input type="hidden" name="orderBy" value="pro_no"/>
					</form>
		            <table id="searchQuotProForm-table" class="table no-border hover" >
		                <thead>
		                <tr>
		                  <th class="text_c" order="asc" col="pro_no" onclick="setOrder(this)">商品代码</th>
		                  <th class="text_l" order="asc" col="pro_name" onclick="setOrder(this)">商品名称</th>
		                  <th class="text_r">涨跌值</th>
		                  <th class="text_r">涨跌幅</th>
		                  <th class="text_r hand" order="asc" col="close_price" onclick="setOrder(this)">最新价</th>
		                  <th class="text_r hand" order="asc" col="open_price" onclick="setOrder(this)">今开价</th>
		                  <th class="text_r">昨收价</th>
		                  <th class="text_r">最高价</th>
		                  <th class="text_r">最低价</th>
		                  <th class="text_r">成交量</th>
		                  <th class="text_r">成交额</th>
		                </tr>
		                </thead>
		                <tbody id="searchQuotProForm-body">
		                </tbody>
		              </table>
		   </div>
	    
	       <div class="">
	       
	           <div class="col-md-5">
	         	<form id="addOrderForm">
					<input type="hidden" size="5" name="pageName" value="bjtesale-add-order"/>
					<input type="hidden" size="5" name="formName" value="pushOrderForm"/>
					<input type="hidden" name="formToken"/>
					<input type="hidden" size="5" name="doCode" value="dymicSql"/>
					<input type="hidden" size="5" name="trsOrder.userId" value="${loginUser.userId}"/>
	           	   	<input type="hidden" size="5" name="trsOrder.userOwner" value="${loginUser.userEname}"/>
	           	   	<input type="hidden" size="5" name="trsOrder.userCname" value="${loginUser.userCname}"/>
	           	   	<input type="hidden" size="5" name="userSettleNo" value="${loginUser.user.cardNum}"/>
	           	   	<input type="hidden" size="5" name="trsOrder.proId" data-name="proId" class="clean"/>
	           	   	<input type="hidden" size="5" name="trsOrder.sysName" value="sale"/>
	           	   	<input type="hidden" size="5" name="trsOrder.orderDate" value=""/>
	           	   	<input type="hidden" size="5" name="trsOrder.orderTime" value=""/>
	           	   	<input type="hidden" size="5" name="trsOrder.orderNo" value=""/>
	           	   	<input type="hidden" size="5" name="tQuotation.closePrice" data-name="lastPrice" class="clean"/>
	           	   	
	           	   	<input type="hidden" size="5" name="constantStatus" value="10"/>
	           	   	<input type="hidden" size="5" name="constantType" value="order_status"/>
	           	   	<input type="hidden" size="5" name="proId" data-name="proId" class="clean"/>
	           	   	<input type="hidden" size="5" name="cateNo" value="bjtesale"/>
	           	   	
		           <ul class="col-md-6 sale">
		           		<li>交易账户：<input type="text" class="input1" name="trsOrder.userEname" readonly="readonly" value="${loginUser.userEname}"/></li>
		           		<li>
			           		&nbsp;&nbsp;&nbsp;&nbsp;
			           		<input type="radio" name="trsOrder.orderFlag" value="buy" checked="checked" onclick="changeFlag('buy')"/> 买入 
			           		&nbsp;&nbsp;&nbsp;&nbsp;
			           		<input type="radio" name="trsOrder.orderFlag" value="sell" onclick="changeFlag('sell')"/> 卖出 
		           		</li>
		           		<li>商品代码：<input type="text" id="addOrderForm_proNo" class="clean" name="trsOrder.proNo" onkeydown="refreshProNo()" data-name="proNo" maxlength="6"/></li>
		           		<li>商品名称：<input type="text" class="clean input1" name="trsOrder.proName" data-name="proName" readonly="readonly" value=""/></li>
		           		<li>报价方式：<select><option value="1">限价委托</option></select></li>
		           		<li>委托价格：<input type="text" id="text_order_price" name="trsOrder.orderPrice" class="clean input2" data-name="buyprice1" data-format="fmoney" style="width:65px;" maxlength="7"/> 元</li>
		           		<!-- <li>
		           		<div class="input-append spinner" data-trigger="spinner">
		           		http://www.kuitao8.com/demo/view/id/1642
							<input value="1" data-rule="currency" type="text">
								<div class="add-on">
									<a class="spin-up" href="javascript:;" data-spin="up">
										<i class="fa fa-sort-up"></i>
									</a>
									<a class="spin-down" href="javascript:;" data-spin="down">
										<i class="fa fa-sort-down"></i>
									</a>
								</div>
							</div
		           		</li>
		           		 -->
		           		<li>委托数量：<input type="text" class="clean" name="trsOrder.orderNum" maxlength="11"/></li>
		           		<li>
		           			<button id="trans-btn" type="button" class="btn btn-danger btn-sm" onclick="submitTransForm('addOrderForm')">买入下单</button>
		           			<button type="button" class="btn btn-default btn-sm pull-right" onclick="cleanData('addOrderForm')"> 重 置 </button> 
		           		</li>
		           </ul>
		           <div class="col-md-6 ">
			           	<ul class="sale2">
			           		<li><span>卖五 </span><span class="clean w2" data-name="sellprice5" data-format="fmoney" onclick="fosmi(this)"></span> <span data-name="sellvalue5" class="clean w3"></span></li>
			           		<li><span>卖四 </span><span class="clean w2" data-name="sellprice4" data-format="fmoney" onclick="fosmi(this)"></span> <span data-name="sellvalue4" class="clean w3"></span></li>
			           		<li><span>卖三 </span><span class="clean w2" data-name="sellprice3" data-format="fmoney" onclick="fosmi(this)"></span> <span data-name="sellvalue3" class="clean w3"></span></li>
			           		<li><span>卖二 </span><span class="clean w2" data-name="sellprice2" data-format="fmoney" onclick="fosmi(this)"></span> <span data-name="sellvalue2" class="clean w3"></span></li>
			           		<li><span>卖一 </span><span class="clean w2" data-name="sellprice1" data-format="fmoney" onclick="fosmi(this)"></span> <span data-name="sellvalue1" class="clean w3"></span></li>
			           	</ul>
			           	<div class="sale-line"></div>
			           	<ul class="sale2">
			           		<li><span>买一 </span><span class="clean w2" data-name="buyprice1" data-format="fmoney" onclick="fosmi(this)"></span> <span data-name="buyvalue1" class="clean w3"></span></li>
			           		<li><span>买二 </span><span class="clean w2" data-name="buyprice2" data-format="fmoney" onclick="fosmi(this)"></span> <span data-name="buyvalue2" class="clean w3"></span></li>
			           		<li><span>买三 </span><span class="clean w2" data-name="buyprice3" data-format="fmoney" onclick="fosmi(this)"></span> <span data-name="buyvalue3" class="clean w3"></span></li>
			           		<li><span>买四 </span><span class="clean w2" data-name="buyprice4" data-format="fmoney" onclick="fosmi(this)"></span> <span data-name="buyvalue4" class="clean w3"></span></li>
			           		<li><span>买五 </span><span class="clean w2" data-name="buyprice5" data-format="fmoney" onclick="fosmi(this)"></span> <span data-name="buyvalue5" class="clean w3"></span></li>
			           	</ul>
			           	<div class="sale-line"></div>
			           	<ul class="sale3">
			           		<li><span>最新 </span><span class="clean w3" id="nowPrice" onclick="fosmi(this)"></span></li>
			           		<li><span>涨幅 </span><span class="clean w3" id="priceUpDownRation">10.00%</span></li>
			           		<li><span>涨停 </span><span class="clean w3" id="priceMax" onclick="fosmi(this)">-</span></li>
			           		<li><span>跌停 </span><span class="clean w3" id="priceMin" onclick="fosmi(this)">-</span></li>
			           	</ul>
		           </div>
			     </form>
			   </div>
			   
			   <div class="col-md-7 ">
	               <div class="row">
	               	<div class="form-group">
	               		<button type="button" class="btn btn-default btn-sm" onclick="refQutoAndGoods()"><i class="fa fa-refresh"></i> 刷新</button>
	               	</div>
						<form id="searchGoodsForm" name="searchGoodsForm">
							<input type="hidden" name="doCode" value="dymicSql"/>
							<input type="hidden" name="pageName" value="trsGoods-list"/>
							<input type="hidden" name="formName" value="searchForm"/>
							<input type="hidden" name="trsGoods.userEname" value="${loginUser.userEname}"/>
						</form>
						<table id="searchGoodsForm-table" class="table table-hover user_table">
							<thead>
								<tr>
									<th class="text_c">商品代码</th>
									<th class="text_c">商品名称</th>
									<th class="text_r">总数量</th>
									<th class="text_r">可用数量</th>
									<th class="text_r">冻结数量</th>
									<!--<th class="text_r">市价</th>
									<th class="text_r">盈亏</th>
									<th class="text_r">成本价</th>
									<th class="text_r">盈亏比</th>
									-->
								</tr>
							</thead>
							<tbody id="searchGoodsForm-body">
							</tbody>
						</table>
						
				 	</div>
			   </div>
			       
	        </div>
	       <!-- right end -->
	      </div>
	      </div>
	      </div>
	 <!-- mainrow end -->
</div>
 <!-- main end -->     
    
   <!-- foot start -->
 <%@include file="/common/sale/foot-user.jsp" %>
 <!-- foot start -->    

</body>
	<script type="text/template" id="searchQuotProForm-template">
	  		<? for ( var i = 0; i < rows.length; i++) {?>
			<? var lastPrice =  rows[i].tQuotation.lastPrice?>
			<? var nowPrice =  rows[i].tQuotation.closePrice?>
			<? var priceUpDown =  fmoney(nowPrice - lastPrice)?>
			<? var priceUpDownRation =  countUpDownRa(priceUpDown,lastPrice)?>
			<? if(strUtil.isNull(nowPrice) || strUtil.isNull(lastPrice)){priceUpDown='';priceUpDownRation='';}?>
				<tr id="pro-quot-<?=rows[i].tQuotation.proId?>" onclick="getQuotByProCode('<?=rows[i].tQuotation.proNo?>')" class="tableRow" data-row-id="<?=i?>">
					<td class="text_c"><span class="qyell"><?=rows[i].tQuotation.proNo?></span></td>
					<td class="text_l"><span class="qyell"><?=strUtil.subStr(rows[i].tQuotation.proName,10)?></span></td>
					<td class="text_r"><span class="<?=getColorClass(0,priceUpDown)?>"><?=priceUpDown?></span></td>
					<td class="text_r"><span class="<?=getColorClass(0,priceUpDown)?>"><?=priceUpDownRation?></span></td>
					<td class="text_r"><span class="<?=getColorClass(lastPrice,nowPrice)?>"><?=fmoneyDoNull(rows[i].tQuotation.closePrice,'')?></span></td>
					<td class="text_r"><span class="<?=getColorClass(lastPrice,rows[i].tQuotation.openPrice)?>"><?=fmoney(rows[i].tQuotation.openPrice)?></span></td>
					<td class="text_r"><span class="qwit"><?=fmoneyDoNull(rows[i].tQuotation.lastPrice,'')?></span></td>
					<td class="text_r"><span class="<?=getColorClass(lastPrice,rows[i].tQuotation.highPrice)?>"><?=fmoneyDoNull(rows[i].tQuotation.highPrice,'')?></span></td>
					<td class="text_r"><span class="<?=getColorClass(lastPrice,rows[i].tQuotation.lowPrice)?>"><?=fmoneyDoNull(rows[i].tQuotation.lowPrice,'')?></span></td>
					<td class="text_r"><?=strUtil.moneyZhuan(rows[i].tQuotation.totalNum,'0')?></td>
					<td class="text_r"><?=strUtil.moneyZhuan(rows[i].tQuotation.totalPrice,'0')?></td>
				</tr>
     		<?}?>
	</script>
	<script type="text/template" id="searchGoodsForm-template">
		<? for ( var i = 0; i < rows.length; i++) {?>
				<tr>
					<td class="text_c"><?=rows[i].proNo?></td>
					<td class="text_c"><?=strUtil.subStr(rows[i].proName,10)?></td>
					<td class="text_r"><?=strUtil.doNull(rows[i].totalNum,'')?></td>
					<td class="text_r"><?=strUtil.doNull(rows[i].useNum,'')?></td>
					<td class="text_r"><?=strUtil.doNull(rows[i].forzenNum,'')?></td>
					<!--<td class="text_r">-</td>
					<td class="text_r"><?=strUtil.doNull(rows[i].costPrice,'')?></td>
					<td class="text_r">-</td>
					<td class="text_r">-</td>
					-->
				</tr>
   		<?}?>
		<?if(rows.length<5){?>
			<? for ( var j = 0; j < (5-rows.length); j++) {?>
				<tr>
					<td class="text_c">&nbsp;</td>
					<td class="text_c">&nbsp;</td>
					<td class="text_r">&nbsp;</td>
					<td class="text_r">&nbsp;</td>
					<td class="text_r">&nbsp;</td>
				</tr>
			<?}?>
		<?}?>
</script>

<script>
var clickMenu= "my-trans";
var token;
var id;
var paramData = {};
var nowDate = new Date().format("yyyy-MM-dd");
function bindKey () {
    jQuery(document).unbind('keydown').bind('keydown', 'left',function (evt){
    	//console.log(evt);
    	alert('left'); 
    	return false;
    	});
    jQuery(document).unbind('keydown').bind('keydown', 'F10',function (evt){ 
    	//alert('right');
    	window.location.href="${ctx}/sendPage/sale/web/trans/F10-model";
    	return false;
    });
    jQuery(document).unbind('keydown').bind('keydown', 'up',function (evt){ 
    	alert('up');
    	return false;
    });
    jQuery(document).unbind('keydown').bind('keydown', 'down',function (evt){
    	alert('down');
    	return false;
    });
};
jQuery(document).ready(bindKey);

$(function () {
	getTableDataQuot();
	getTableDataGoods();
	setToken();
});

//清空数据
function cleanData(id){
	$('#'+id).find(".clean").val("");//按照样式清空；
	$('#'+id).find(".clean").text("");//按照样式清空；
}
//查询行情
function getTableDataQuot(){
	var searchFromId = "searchQuotProForm";
	deleteAllRow(searchFromId+'-table');
	$.ajax({
		   type:'get',
		   url:common_list_url,
		   data:$("#"+searchFromId).serialize()+getCurrentPage(common_list_url+"?"+$("#"+searchFromId).serialize(),10),
		   dataType:'json',
		   success: function(myData){
			//console.log(myData);
			var data = baidu.template(searchFromId+"-template",eval(myData));
			$("#"+searchFromId+"-body").html(data);
		/**	

					var menu = new BootstrapMenu('.tableRow', {
					  fetchElementData: function($rowElem) {
					    var rowId = $rowElem.data('rowId');
					    return myData.rows[rowId];
					  },
					  
					  actionsGroups: [
					    ['setMark', 'setAlarm' ]
					  ],
			
					  actions: {
					    customer: {
					      name: '加入自选',
					      iconClass: 'fa-user-plus',
					      onClick: function(row) {
					      },
					      isEnabled: function(row) {
					      }
					    },
					    dataOut: {
					      name: '数据导出',
					      iconClass: 'fa-bar-chart',
					      onClick: function(row) {
					      },
					      isEnabled: function(row) {
					      }
					    },
					    setMark: {
					      name: '标记',
					      iconClass: 'fa-star',
					      onClick: function(row) {
					      },
					      isShown: function(row) {
					      }
					    },
					    setAlarm: {
					      name: '预警',
					      iconClass: 'fa fa-bell-o',
					      onClick: function(row) {
					      },
					      isShown: function(row) {
					      }
					    }
					  }
					});
			**/
			
			
			  var option= {
					   ele:$("#"+searchFromId+"-page")[0],
					   total:myData.total,
					   fn:getTableDataQuot,
					   url:common_list_url+"?"+$("#"+searchFromId).serialize()
				   }
			generatePages(option);
		   }
		});	
	//setTimeout("getTableDataQuot()",2000);
  }
//查询我的持仓
function getTableDataGoods(){
	var searchFromId = "searchGoodsForm";
	deleteAllRow(searchFromId+'-table');
	$.ajax({
		   type:'get',
		   url:common_list_url,
		   data:$("#"+searchFromId).serialize()+getCurrentPage(common_list_url+"?"+$("#"+searchFromId).serialize(),10),
		   dataType:'json',
		   success: function(myData){
			//console.log(myData);
			var data = baidu.template(searchFromId+"-template",eval(myData));  
			$("#"+searchFromId+"-body").html(data);
			  var option= {
					   ele:$("#"+searchFromId+"-page")[0],
					   total:myData.total,
					   fn:getTableDataGoods,
					   url:common_list_url+"?"+$("#"+searchFromId).serialize()
				   }
			generatePages(option);
		   }
		});	
  }

//输入商品代码后触发
function refreshProNo(){
	var proNo = $("#addOrderForm_proNo").val();
	if(strUtil.isNull(proNo) || proNo.length < 6){
		return;
	}
	getQuotByProCode(proNo);
}

//初始化指定商品的行情信息
function getQuotByProCode(proNo){
	cleanData("addOrderForm");
	var paramLoadData = {"pageName":"t-quotation","formName":"searchForm","tQuotation.w_proNo":proNo};
	$.ajax({
	    type:'get',
	   	url:common_info_url,
	    data: paramLoadData,
	    async:false,
	    dataType:"json",
	    success: function(myData){
	    	console.log(myData);
	    	FormUtil.loadView("", myData.tQuotation);
	    	var lastPrice = myData.tQuotation.lastPrice;
	    	var nowPrice = myData.tQuotation.closePrice;
	    	//卖盘
	    	//买盘
	    	
	    	//最新价
	    	if(!strUtil.isNull(nowPrice) && !strUtil.isNull(lastPrice)){
				$("#nowPrice").html("<label class='"+getColorClass2(lastPrice,nowPrice)+"'>"+fmoney(nowPrice)+"</label>");
				$("#nowPrice").attr("data-val",nowPrice);
		    	//计算涨幅
		    	var priceUpDown = fmoney(nowPrice - lastPrice);
		    	var priceUpDownRation =  countUpDownRa(priceUpDown,lastPrice);
				$("#priceUpDownRation").html("<label class='"+getColorClass2(0,priceUpDown)+"'>"+priceUpDownRation+"</label>");
	    	}else{
	    		$("#nowPrice").html("<label class='"+getColorClass2(lastPrice,nowPrice)+"'>--</label>");
				$("#priceUpDownRation").html("<label class='"+getColorClass2(0,priceUpDown)+"'>--</label>");
	    	}
			//计算涨停，跌停。
	    	countMaxMinPrice(lastPrice,myData.tQuotation.proId);
	  	}
	});
}

function deleteAllRow(tableId){
	var tb = document.getElementById(tableId);
	if(tb){
	     var rowNum=tb.rows.length;
	     for (var i=1;i<rowNum;i++){
	         tb.deleteRow(i);
	         rowNum=rowNum-1;
	         i=i-1;
	     }
     }
}


function cannel(modalId){
	$('#'+modalId).modal('hide');
}



function submitTransForm(formId){
	var proNo = $("#"+formId).find("input[name='trsOrder.proNo']").val();
	var proName = $("#"+formId).find("input[name='trsOrder.proName']").val();
	var orderPrice = $("#"+formId).find("input[name='trsOrder.orderPrice']").val();
	var orderNum = $("#"+formId).find("input[name='trsOrder.orderNum']").val();
	var orderFlag = $("#"+formId).find("input[name='trsOrder.orderFlag']:checked").val();
	if(strUtil.isNull(proNo)){
		layer.alert('请选择商品代码！', {closeBtn: 0 });
		return;
	}
	if(strUtil.isNull(orderPrice)){
		layer.alert('请输入委托价格！', {closeBtn: 0 });
		return;
	}
	var re1 = /^([1-9]\d*(\.\d*[1-9])?)|(0\.\d*[1-9])$/;  
	//if(!re1.test(orderPrice)){
	if(isNaN(orderPrice)){
		layer.alert('委托价格输入不合法！', {closeBtn: 0 });
		$("#"+formId).find("input[name='trsOrder.orderPrice']").val("");
		return;
	}
	if(strUtil.isNull(orderNum)){
		layer.alert('请输入委托数量！', {closeBtn: 0 });
		return;
	}
	var re2 = /^\+?[1-9]\d*$/ ;  
	if(!re2.test(orderNum)){
		layer.alert('委托数量输入不合法！', {closeBtn: 0 });
		$("#"+formId).find("input[name='trsOrder.orderNum']").val("");
		return;
	}
	//$("#"+formId).find("input[name='trsOrder.orderPrice']").val(fmoney(orderPrice));
	var orderType = ((orderFlag=="buy")?"买入":"卖出");
	//alert(orderFlag+"-"+orderType);
	var tipMsg = "买卖方向："+orderType+"<br/>商品代码："+proNo+"<br/>商品名称："+proName+"<br/>委托价格：￥"+fmoney(orderPrice)+"<br/>委托数量："+orderNum;
	//缺省值
	var tmps = new Date().getTime();
	$("#"+formId).find("input[name='trsOrder.orderDate']").val(nowDate);
	$("#"+formId).find("input[name='trsOrder.orderNo']").val("T"+tmps);
	$("#"+formId).find("input[name='trsOrder.orderTime']").val(tmps);
	var index_submit = layer.confirm(tipMsg+"<br/><br/>您是否确认以上委托？", {btn: ['确认'+orderType,'取消'],closeBtn: 0,offset: '220px'}
	, function(){
		layer.close(index_submit);
		var index_load = layer.msg("数据正在提交。。。", {shade: false,offset: '220px'});
		$.ajax({
		    type:'post',
		    url:common_submit_url,
		    data:$("#"+formId).serialize(),
		    //async:false,
		    dataType:'json',
		    success: function(myData){ 
		     //console.log(myData);
		        if(myData.flag=="T"){
		        	//layer.alert("委托成功！");
		        	refreshProNo();
		        	//getTableDataQuot();
		        	getTableDataGoods();
		    	}else{
		    		layer.alert(MsgToos.getMsg(myData.msg));
		    	}
		        layer.close(index_load);
		  	}
		});	
	})
	
 }
	
//切换选择按钮
function changeFlag(flag){
	if("buy"==flag){
		$("#trans-btn").text("买入下单");
		$("#trans-btn").removeClass("btn-success").addClass("btn-danger");
	}else if("sell"==flag){
		$("#trans-btn").text("卖出下单");
		$("#trans-btn").removeClass("btn-danger").addClass("btn-success");
	}
}
//控制红绿白颜色变化
function getColorClass(a,b){
	if(a*1==b*1)return 'qwit';
	if(a*1< b*1)return 'qred';
	if(a*1> b*1)return 'qgree';
	else return 'qwit';
}
function getColorClass2(a,b){
	if(a*1==b*1)return '333';
	if(a*1< b*1)return 'qred';
	if(a*1> b*1)return 'qblue';
	else return '333';
}
//计算涨跌幅比例
function countUpDownRa(priceUpDown,lastPrice){
	return fmoney(priceUpDown/lastPrice*100)+"%";
}
function setOrder(o){
	var obj = $(o);
	var order = obj.attr("order");
	var orderBy = obj.attr("col")+" "+order;
	$("#searchQuotProForm").find("input[name='orderBy']").val(orderBy);
	getTableDataQuot();
	
	if(order=="desc"){
		obj.attr("order","");
	}else{
		obj.attr("order","desc");
	}
}


//获取交易规则
function countMaxMinPrice(lastPrice,proId){
	  var paramData = {"pageName":"trs-rules-pro","formName":"searchForm","trsRulesPro.w_showFlag":"T","trsRulesPro.w_rulesType":"guadan","trsRulesPro.w_prodId":proId,"orderBy":"trsRulesPro.rules_no"};
	  $.ajax({
		   type:'get',
		   url:common_list_url,
		   data:paramData,
		   dataType:'json',
		   success: function(myData){
			   console.log(myData);
			   if(myData.flag="T"){
				  for(var i=0;i<myData.total;i++){
					  var rulesNo = myData.rows[i].trsRulesPro.rulesNo;
					  var paramVal = myData.rows[i].trsRulesPro.paramNo;
					  if("order03"==rulesNo){
						  var maxVal = paramVal;
						  var priceMax = fmoney(lastPrice * (1+maxVal*0.01));
						  $("#priceMax").html("<label class='"+getColorClass2(lastPrice,priceMax)+"'>"+priceMax+"</label>");
						  $("#priceMax").attr("data-val",priceMax);
					  }else if("order04"==rulesNo){
						  var minVal = paramVal;
						  var priceMin = fmoney(lastPrice * (1-minVal*0.01));
						  $("#priceMin").html("<label class='"+getColorClass2(lastPrice,priceMin)+"'>"+priceMin+"</label>");
						  $("#priceMin").attr("data-val",priceMin);
					  }
				  }
			   }
		   }
	  }); 

}

//抓取选中的价格到委托价格文本框
function fosmi(ob){
	var obj = $(ob);
	$("#text_order_price").val(obj.attr("data-val"));
}

//手工刷新
function refQutoAndGoods(){
	getTableDataQuot();
	getTableDataGoods();
}
/**
//获取行情推送信息
var goEasy = new GoEasy({
    appkey: 'fcdd060e-c3ee-4003-bdd7-d68785a77d19'
});
goEasy.subscribe({
 channel: 'pro_quotation',
 onMessage: function(message){
	 console.log(message);
    // alert('收到：'+message.content);
     refProQuot(message.content);
 }
});
 **/

$(function () {
    if (!window.WebSocket) {
        alert("FATAL: WebSocketProcessIndex not natively supported. This demo will not work!");
    }
    var wsocket;
    var websocketUrl = "ws://39.104.104.181:11006/websocket/sale?sysPass=e0cea4bb45e36c115356e46910c354af";
    wsocket = new WebSocket(websocketUrl);
    wsocket.onopen = function() {
        console.log("WebSocket onopen",websocketUrl+"[WebSocket#onopen]");
    }
    wsocket.onmessage = function(e) {
        // $("#log").append("[WebSocket#onmessage] Message: '" + e.data + "'\n");
        console.log("WebSocket onmessage",e);
        console.log("WebSocket data",e.data);
        var myData = JSON.parse(e.data).message;
        if(myData){
            refProQuot(myData.proId);
        }
    }
    wsocket.onclose = function() {
        console.log("WebSocket onclose","[WebSocket#onclose]");
    }
});


//刷新指定商品交易行情
function refProQuot(proId){
	var trObj = $("#pro-quot-"+proId);
	//alert(trObj.html());
	//alert(trObj.find("td").eq(1).html());
	var paramData = {"pageName":"t-quotation","formName":"searchForm","tQuotation.w_proId":proId};
	  $.ajax({
		   type:'get',
		   url:common_info_url,
		   data:paramData,
		   dataType:'json',
		   success: function(myData){
			   console.log(myData);
			   if(myData){
				   	var obj = myData.tQuotation;
				   	var lastPrice =  obj.lastPrice
					var nowPrice =  obj.closePrice
					var priceUpDown =  fmoney(nowPrice - lastPrice)
					var priceUpDownRation =  countUpDownRa(priceUpDown,lastPrice)
					if(strUtil.isNull(nowPrice) || strUtil.isNull(lastPrice)){priceUpDown='';priceUpDownRation='';}
				   	trObj.find("td").eq(2).html("<span class='"+getColorClass(0,priceUpDown)+"'>"+priceUpDown+"</span>");
				   	trObj.find("td").eq(3).html("<span class='"+getColorClass(0,priceUpDown)+"'>"+priceUpDownRation+"</span>");	
				   	trObj.find("td").eq(4).html("<span class='"+getColorClass(lastPrice,nowPrice)+"'>"+nowPrice+"</span>");
				   	trObj.find("td").eq(7).html("<span class='"+getColorClass(lastPrice,obj.highPrice)+"'>"+fmoneyDoNull(obj.highPrice,'')+"</span>");
				   	trObj.find("td").eq(8).html("<span class='"+getColorClass(lastPrice,obj.lowPrice)+"'>"+fmoneyDoNull(obj.lowPrice,'')+"</span>");
				   	trObj.find("td").eq(9).html(strUtil.moneyZhuan(obj.totalNum,0));
				   	trObj.find("td").eq(10).html(strUtil.moneyZhuan(obj.totalPrice,0));
				 /**  <td class="text_c"><span class="qyell"><?=rows[i].proNo?></span></td>
					<td class="text_l"><span class="qyell"><?=strUtil.subStr(rows[i].proName,5)?></span></td>
					<td class="text_r"><span class="<?=getColorClass(0,priceUpDown)?>"><?=priceUpDown?></span></td>
					<td class="text_r"><span class="<?=getColorClass(0,priceUpDown)?>"><?=priceUpDownRation?></span></td>
					<td class="text_r"><span class="<?=getColorClass(lastPrice,nowPrice)?>"><?=strUtil.subStr(rows[i].closePrice,'-')?></span></td>
					<td class="text_r"><span class="<?=getColorClass(lastPrice,rows[i].openPrice)?>"><?=strUtil.subStr(rows[i].openPrice,'-')?></span></td>
					<td class="text_r"><span class="qwit"><?=strUtil.subStr(rows[i].lastPrice,'-')?></span></td>
					<td class="text_r"><span class="<?=getColorClass(lastPrice,rows[i].highPrice)?>"><?=strUtil.subStr(rows[i].highPrice,'-')?></span></td>
					<td class="text_r"><span class="<?=getColorClass(lastPrice,rows[i].lowPrice)?>"><?=strUtil.subStr(rows[i].lowPrice,'-')?></span></td>
					<td class="text_r"><?=strUtil.subStr(rows[i].totalNum,'-')?></td>
					<td class="text_r"><?=strUtil.subStr(rows[i].totalPrice,'-')?></td>
					**/
			   }
		   }
	  }); 
}
/**
$(function(){
	refTimer();
});
function refTimer(){
	$("#label-timer").text(new Date().format("hh:mm:ss"));
	setTimeout("refTimer()",900);
}
**/
</script>

</html>
